package org.hk.proxy.server.web;

import org.hk.proxy.common.constant.ApiStateEnum;

public class Result<T> {
    private Integer code;
    private String msg;
    private T data;
    private Result(T t) {
        this(ApiStateEnum.SUCCESS);
        this.data = t;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    private Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Result(ApiStateEnum resultEnum) {
        this(resultEnum.getCode(), resultEnum.getName());
    }

    public static <T> Result<T> success(T t) {
        return new Result(t);
    }
    public static Result of(ApiStateEnum resultEnum){
        return new Result(resultEnum.getCode(), resultEnum.getName());
    }

    public static Result of(Integer code, String msg){
        return new Result(code, msg);
    }
}
